1bashThis demonstrates iterating over all arguments passed to a script using the "$@" variable.for arg in "$@"; do echo "Argument: $arg" donebash internalloopsfor loopargument iteration
2bashThis demonstrates the use of an integer variable and a conditional while loop in Bash to decrement and print values.declare -i counter counter=10 while [ $counter -gt 2 ]; do echo The counter is $counter counter=counter-1 donebash internalloopswhile loopconditional
3bashThis demonstrates three different for loop examples in Bash, including iterating over a numerical range, a predefined list of filenames, and all files in the current directory, showcasing various file manipulation techniques.for i in {0..10..2} do echo "Index: $i" done for filename in file1 file2 file3 do echo "Content: " >> $filename done for filename in *; do echo "Content: " >> $filename donebash internalloopsfor loopnumerical range iteration
4bashThis demonstrates a C-style for loop to iterate over a range of numbers.for ((i = 0 ; i < 10 ; i++)); do echo "$i" donebash internalloopsfor loopC-style
5bashThis demonstrates a basic for loop in Bash, iterating over a list of items and printing each one.for item in a b c; do echo "$item"; donebash internalloopsfor loopbasic
6bashThis demonstrates a line-by-line while loop to process each line from a file.cat file.txt | while read line; do echo $line donebash internalloopswhile loopline-by-line
7bashThis demonstrates reading and processing a file line by line using a while loop in Bash.while read -r line; do echo "$line" done <file.txtbash internalloopswhile loopline-by-line
8bashThis demonstrates a globbing (wildcards) for loop in Bash to iterate over files matching a specific pattern.for item in ./example-dir/example-pattern*; do echo "$item" donebash internalloopsfor loopglobbing (wildcard)
9bashThis demonstrates iterating over a range of numbers with a specified step size using a for loop in Bash.for i in {5..50..5}; do echo "Welcome $i" donebash internalloopsfor looprange with step
10bashThis demonstrates a forever (infinite) while loop that executes a command and sleeps for 10 seconds repeatedly.while true; do # example_command_to_execute echo "--- sleep 10 ---" sleep 10 donebash internalloopswhile loopforever (infinite)
11bashThis demonstrates reading and processing a file line-by-line using a while loop in Bash.while read -r line; do echo "$line" done <file.txtbash internalloopswhile loopline-by-line
12bashThis demonstrates a for loop iterating over files matching a pattern in a directory.for i in /etc/rc.*; do echo "$i" donebash internalloopsfor loopglobbing (wildcard)
13bashThis code lists all items in the current directory using ls, stores them in a variable, and iterates over each item to print its name.items=`ls .` for item in $items; do echo "$item" donebash internalloopsfor loopvariable expansion
14bashThis demonstrates the use of ranges in a for loop to iterate over numbers and print a message for each iteration.for i in {1..5}; do echo "Welcome $i" donebash internalloopsfor looprange iteration
15bashThis demonstrates iterating over an array in Bash using a for loop.for i in "${arrayName[@]}"; do echo "$i" donebash internalloopsfor looparray iteration
16bashThis demonstrates iterating over an array in Bash using a for loop.for val in "${sounds[@]}"; do echo "$val" donebash internalloopsfor looparray iteration
17bashThis demonstrates a while loop iterating over items from a here-document (heredoc) in Bash.while read -r item; do echo "$item" done <<EOF a b c EOFbash internalloopswhile loopline-by-line
18bashThis demonstrates a for loop using the seq command to iterate over a sequence of numbers.for index in `seq 1 10`; do echo "$index"; donebash internalloopsfor loopbasic
19bashThis demonstrates iterating over the keys of an associative array in Bash.for key in "${!sounds[@]}"; do echo "$key" donebash internalloopsfor loopassociative array keys
20bashThis script converts .HEIC image files to .JPG format using the sips command. It searches for files matching the pattern IMG_04*.HEIC in the current directory and its subdirectories, then converts each file to JPEG format with a quality setting of 70. This demonstrates batch image format conversion.for i in `find . -name "IMG_04*.HEIC"`; do sips -s format jpeg -s formatOptions 70 "${i}" --out "${i%HEIC}JPG"; donebash internalloopsfor loop